home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Library
/
RoseWare - Network Support Library.iso
/
apidev
/
mhs_c.arc
/
INPOST.ARC
/
COMMANDS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-06-27
|
4KB
|
172 lines
/* ****************************** COMMANDS.C ****************************** */
#include "cctypes.h"
#define FIRST_WORD_SIZE 37
extern char Out[];
extern char currentLine[];
extern int ErrorsInThisFile;
extern int warningFound;
extern int lineNumber;
extern int InFile;
extern MCB MCBStruct;
extern char messageBuffer[];
extern char workArea[];
extern void AddCurrentLineToMessageBuffer();
extern int GetNextLine();
extern void GetFirstWord();
void WriteAttachmentFile();
int CreateMCBLine(type)
int type;
{
int returnCode = NO_ERROR, ccode = 0, bytes;
char fileName[81], temp[60], *p;
char firstWord[FIRST_WORD_SIZE];
static int inMessage = 0;
static int inTextItem = 0;
static int hasAttachment = 0;
extern void InitMCB();
Out[0] = '\0';
warningFound = 0;
switch ( type ) {
case MESSAGE:
if ( inMessage ) {
WriteMCBFile();
/* STUB call seal from here */
InitMCB();
}
inMessage++;
break;
case FROM:
/* for now, just take this line as being the first name STUB */
/* the at (@) part is supplied to INPOST by the Connectivity */
/* Manager as the first argument. */
/* STUB strip off the first thing only */
temp[0] = '\0';
p = stptok(¤tLine[6], temp, sizeof(temp), " ");
if ( strlen(temp) )
strcpy(MCBStruct.originatingUsername, temp);
break;
case CONTENTS:
/* get the next line; if we have a TExt, FIle, or GRaphic item... */
GetNextMessageLine:
lineNumber++;
inTextItem++;
bytes = GetNextLine();
if ( bytes == 0 )
break;
/* else */
GetFirstWord(firstWord); /* gets the first word of the current line */
ccode = GetCommandType(firstWord);
if ( ccode != -1 )
CreateMCBLine(ccode); /* ccode is the switch table index */
else {
AddCurrentLineToMessageBuffer();
goto GetNextMessageLine;
}
inTextItem = 0;
break;
case FORWARDED_BY:
/* STUB ignore for now */
break;
case DATE:
/* ignore */
break;
case TO:
/* STUB */
temp[0] = '\0';
p = stptok(¤tLine[4], temp, sizeof(temp), " ");
if ( strlen(temp) )
strcpy(MCBStruct.destinationUsername, temp);
p += 4;
if ( *p != '\0' ) /* this shouldn't happen */
strcpy(MCBStruct.destinationHost, p);
break;
case CC:
/* STUB ignore for now */
break;
case SUBJECT:
if ( strlen(currentLine) > 9 )
strcpy(MCBStruct.messageSubject, ¤tLine[9]);
break;
case TEXT_ITEM:
GetNextLine();
goto GetNextMessageLine;
break;
case GRAPHICS_ITEM:
/* STUB - MCB only allows one attachment for now */
if ( hasAttachment ) break;
/* strip off the filename part and set this MCB field to that part */
fileName[0] = '\0';
p = stptok(¤tLine[15], fileName, sizeof(fileName), " ");
MCBStruct.contentTypeOfAttachmentFile = 9000;
goto DoAttachment;
break;
case FILE_ITEM:
/* STUB remember, the MCB format allows us only one attachment file. */
if ( hasAttachment ) break;
/* strip off the filename part and set this MCB field to that part */
fileName[0] = '\0';
p = stptok(¤tLine[11], fileName, sizeof(fileName), " ");
MCBStruct.contentTypeOfAttachmentFile = 9000;
DoAttachment:
hasAttachment++;
strcpy(MCBStruct.attachmentFilename, fileName);
/* this will get the number of bytes to copy to the attachment file */
GetNextLine();
GetNextLine();
WriteAttachmentFile(fileName, atoi(currentLine));
/* open a file by this name in the temp area */
break;
default:
;
}
return(returnCode);
}
void WriteAttachmentFile(fileName, fileSize)
char *fileName;
int fileSize;
{
int handle, bytesRead, temp = 0;
char *buffer;
long fSize;
buffer = (char *)(malloc(30000)); /* allocate statically ? */
if ( buffer == (char *)NULL )
return;
/* else */
handle = open(fileName, 0x8301, 0); /* open for write/create */
if ( handle == -1 ) {
free(buffer);
return;
}
while ( fileSize > 0 ) {
temp = fileSize < 30000 ? fileSize : 30000;
bytesRead = read(InFile, buffer, temp);
if ( bytesRead )
write(handle, buffer, bytesRead);
fileSize -= bytesRead;
}
close(handle);
free(buffer);
}